package com.atguigu.gmall.order.handler;

import com.atguigu.gmall.common.bean.ResponseVo;
import com.atguigu.gmall.common.exception.GmallAsyncException;
import com.atguigu.gmall.common.exception.GmallException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GmallExceptionHandler {

    @ExceptionHandler(value = GmallException.class)
    public String exception(GmallException exception){
        System.out.println("转发或重定向接口出现异常："+exception.getMessage());
        return "error";
    }
    @ResponseBody
    @ExceptionHandler(value = GmallAsyncException.class)
    public ResponseVo exception(GmallAsyncException exception){
        System.out.println("异步请求接口出现异常："+exception.getMessage());
        return ResponseVo.fail(exception.getMessage());
    }
}
